package com.qef.com.mmovie.mvp.interactor;

import com.orhanobut.logger.Logger;
import com.qef.com.mmovie.api.ApiSever;
import com.qef.com.mmovie.api.VideoListBean;
import com.qef.com.mmovie.entity.SubscriptionDetailsEntity;
import com.qef.com.mmovie.net.IGetDataDelegate;
import com.qef.com.mmovie.utils.RxUtil;

import javax.inject.Inject;

import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

import static android.R.attr.data;

/**
 * Created by guangjiego on 2017/3/22.
 */

public class SubscriptionDetailsInteractor {
    private ApiSever apiSever;

    @Inject
    public SubscriptionDetailsInteractor(ApiSever apiSever) {
        this.apiSever = apiSever;
    }

    public Disposable loadPlayList(int start, int numm, final IGetDataDelegate<SubscriptionDetailsEntity> iGetDataDelegate) {
        return apiSever.getSubscrptionDetailsList(start, numm).
                compose(RxUtil.background())
                .subscribe(new Consumer<SubscriptionDetailsEntity>() {
                               @Override
                               public void accept(@NonNull SubscriptionDetailsEntity videoListBean) throws Exception {
                                   iGetDataDelegate.getDataSuccess(videoListBean);
                               }
                           }, new Consumer<Throwable>() {
                               @Override
                               public void accept(@NonNull Throwable throwable) throws Exception {
                                   throwable.printStackTrace();
                                   Logger.i("xxxxxxxxx-----------------");
                                   iGetDataDelegate.getDataError(throwable);
                               }
                           }
                );
    }
}
